@extends('admin.layouts.base')

@section('title','控制面板')

@section('pageHeader','控制面板')

@section('pageDesc','DashBoard')

@section('content')

    <div class="row page-title-row" style="margin:5px;">
        <div class="col-md-6">
        </div>
        <div class="col-md-6 text-right">
			<a href="javascript:;" onclick="batchDel()" class="btn btn-danger btn-md" style="">
                <i class="fa fa-minus-circle"></i> 批量删除
            </a>
			<a href="/admin/term/create" class="btn btn-success btn-md">
                <i class="fa fa-plus-circle"></i> 添加条件
            </a>
        </div>
    </div>

    <div class="row">
        <div class="col-xs-12">
            <div class="box">

                @include('admin.partials.errors')
                @include('admin.partials.success')
                <div class="box-body">
                    <table id="tags-table" class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th data-sortable="false" class="hidden-sm "><input id="all" type="checkbox"/>全选</th>
                            <th class="hidden-sm">条件名</th>
                            <th class="hidden-sm">站点类型</th>
							<th class="hidden-sm">设备类型</th>
							<th class="hidden-sm">区域限制</th>
                            <th class="hidden-md">状态</th>
                            <th class="hidden-md">修改时间</th>
                            <th data-sortable="false">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="modal-delete" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这个条件吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="deleteForm" method="POST" action="/admin/term">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="DELETE">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>

    {{--批量删除--}}
    <div class="modal fade" id="modal-batch-del" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这些条件吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="batchDelForm" method="POST" action="/admin/term">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="DELETE">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>
@stop
@section('js')
    <script>
        $(function () {
            var table = $("#tags-table").DataTable({
                language: {
                    "sProcessing": "处理中...",
                    "sLengthMenu": "显示 _MENU_ 项结果",
                    "sZeroRecords": "没有匹配结果",
                    "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                    "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                    "sInfoPostFix": "",
                    "sSearch": "搜索:",
                    "sUrl": "",
                    "sEmptyTable": "表中数据为空",
                    "sLoadingRecords": "载入中...",
                    "sInfoThousands": ",",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上页",
                        "sNext": "下页",
                        "sLast": "末页"
                    },
                    "oAria": {
                        "sSortAscending": ": 以升序排列此列",
                        "sSortDescending": ": 以降序排列此列"
                    }
                },
                order: [[6, "desc"]],
                serverSide: true,
                ajax: {
                    url: '/admin/term/index',
                    type: 'POST',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    }
                },
                "columns": [
                    {"data": "id"},
                    {"data": "name"},
					{"data": "station_type",render:function(data){ @foreach($station_type as $sk=>$st) if(data=='{{$sk}}'){return '{{$st}}';} @endforeach}},
					{"data": "device_type",render:function(data){ @foreach($device_type as $dk=>$dt) if(data=='{{$dk}}'){return '{{$dt}}';} @endforeach}},
                    {"data": "area_config",render:function(data){ @foreach($area_config as $ak=>$ac) if(data=='{{$ak}}'){return '{{$ac}}';} @endforeach}},
                    {"data": "status",render:function(data){
						switch(data){
							case 0: return "<span style='color:black;'>禁用</span>";
							case 1: return "<span style='color:green;'>正常</span>";
						}
					}},
                    {"data": "updated_at",render:function(data,type,row){ return data;}},
                    {"data": "action"}
                ],
                columnDefs: [
                    {
                        'targets': -1, "render": function (data, type, row)
                        {
							var caozuo = '';
								caozuo += '<a style="margin:3px;" href="/admin/term/' + row['id'] + '/edit" class="X-Small btn-xs text-success "><i class="fa fa-edit"></i> 编辑</a>';
								caozuo += '<a style="margin:3px;" href="#" attr="' + row['id'] + '" class="delBtn X-Small btn-xs text-danger "><i class="fa fa-times-circle-o"></i> 删除</a>';
                           
						   return caozuo;
                        }
					},
                    {
                        'targets': 0, "render": function (data, type, row)
                        {
							 var caozuoCB = '';
								caozuoCB += '<div class="checkbox hidden-sm"><label><input class="itemCB" name="itemCB[]" type="checkbox" value="' + row['id'] + '"></label></div>';
                            return caozuoCB;
                        }
                    }
                ]
            });

            table.on('preXhr.dt', function () {
                loadShow();
            });

            table.on('draw.dt', function () {
                loadFadeOut();
            });

            table.on('order.dt search.dt', function () {
                table.column(0, {search: 'applied', order: 'applied'}).nodes().each(function (cell, i) {
                    cell.innerHTML += (i + 1);
                });
            }).draw();

            $("table").delegate('.delBtn', 'click', function () {
                var id = $(this).attr('attr');
                $('.deleteForm').attr('action', '/admin/term/' + id);
                $("#modal-delete").modal();
            });
			
			$(".cogs-update").click(function(){
				$("#modal-cogs-update").modal();
			});
        });
		function setUpdateId(){
			var valArr = new Array;
			$(".itemCB").each(function (i) {
				if (this.checked) {
					valArr.push($(this).val());
				}
			});
			var ids = valArr.join(',');
			$("input[name=update_id]").val(ids);
			if($("input[name=update_id]").val()==''){
				alert("请选择需要修改的选项！");
				return false;
			}
			return true;
		}
    </script>
@stop